package com.magina.antiPro.component;

import com.magina.antiPro.config.ControllerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.Collections;

@Configuration("DsmtWebConfiguration")
@Primary
public class DsmtWebConfiguration implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getUserAuthRestInterceptor()).addPathPatterns("/**");
    }


    @Bean
    ControllerInterceptor getUserAuthRestInterceptor() {
        return new ControllerInterceptor();
    }

    /**
     * 需要用户和服务认证判断的路径
     *
     * @return
     */
    private ArrayList<String> getIncludePathPatterns() {
        ArrayList<String> list = new ArrayList<>();
        String[] urls = {
                //"/user/**",
                //"/resource/**",
                //"/permissions/**"
        };
        Collections.addAll(list, urls);
        return list;
    }

}